package config

import (
	"log"

	"github.com/spf13/viper"
)

// Config 所有配置
type Config struct {
	ServePath string `mapstructure:"serve"`
	ServeURL  string `mapstructure:"url"`
	AdminPath string `mapstructure:"admin"`
	FrontPath string `mapstructure:"front"`
	Port      string `mapstructure:"port"`
}

const defaultConfigFile = "cfg"

func InitCfg(c *Config) {
	v := viper.New()
	v.SetConfigName(defaultConfigFile)
	v.AddConfigPath(".")
	if err := v.ReadInConfig(); err != nil {
		log.Fatalf("Fatal error config file: %s", err)
	}
	if err := v.Unmarshal(c); err != nil {
		log.Fatalf("Fatal error config file: %s", err)
	}
}
